{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "weighted-voltage",
   "metadata": {},
   "source": [
    "## 导入依赖"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "worth-seven",
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "import numpy as np\n",
    "import yaml\n",
    "# 自定义库\n",
    "from arm5dof_uservo import Arm5DoFUServo\n",
    "from arm_application import ArmApplication\n",
    "from config import *"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "legitimate-future",
   "metadata": {},
   "source": [
    "## 创建机械臂应用案例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "partial-imaging",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 创建机械臂\n",
    "arm = Arm5DoFUServo(is_debug=True)\n",
    "# 创建机械臂应用\n",
    "arm_app = ArmApplication(arm, is_debug=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "future-commitment",
   "metadata": {},
   "source": [
    "## 测试物块定点抓取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "banned-surface",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "运动到 wx=55.00, wy=80.00, wz=65.00\n",
      "运动到 arm_x=264.13, arm_y=93.44, wz=46.53\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING:root:机械臂末端不能到达: [264.127, 93.437, -5.2435432495750725] 俯仰角=2.3771592455017165 横滚角=3.141592653589793\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "运动到 wx=55.00, wy=80.00, wz=15.00\n",
      "运动到 arm_x=264.13, arm_y=93.44, wz=-3.47\n",
      "运动到 wx=55.00, wy=80.00, wz=65.00\n",
      "运动到 arm_x=264.13, arm_y=93.44, wz=46.53\n"
     ]
    }
   ],
   "source": [
    "# 手动设定物块的位置，单位cm\n",
    "wx = 55\n",
    "wy = 80\n",
    "wz = 10\n",
    "# 机械臂物块抓取\n",
    "arm_app.grab_cubic(wx, wy, wz)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "executed-owner",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 手动设定物块的位置，单位cm\n",
    "wx = 0\n",
    "wy = 0\n",
    "wz = 10.0\n",
    "# 机械臂物块抓取\n",
    "arm_app.grab_cubic(wx, wy, wz)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "dietary-depth",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 手动设定物块的位置，单位cm\n",
    "wx = -55\n",
    "wy = 0\n",
    "wz = 10.0\n",
    "# 机械臂物块抓取\n",
    "arm_app.grab_cubic(wx, wy, wz)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "noted-trouble",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "运动到 wx=-55.00, wy=-80.00, wz=65.00\n",
      "运动到 arm_x=156.21, arm_y=-67.99, wz=46.53\n",
      "运动到 wx=-55.00, wy=-80.00, wz=15.00\n",
      "运动到 arm_x=156.21, arm_y=-67.99, wz=-3.47\n",
      "运动到 wx=-55.00, wy=-80.00, wz=65.00\n",
      "运动到 arm_x=156.21, arm_y=-67.99, wz=46.53\n"
     ]
    }
   ],
   "source": [
    "# 手动设定物块的位置，单位cm\n",
    "wx = -55\n",
    "wy = -80\n",
    "wz = 10.0\n",
    "# 机械臂物块抓取\n",
    "arm_app.grab_cubic(wx, wy, wz)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
